package test;

import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class Fbolaqie {
    public static void main(String[] args) {
        Scanner in =new Scanner(System.in);
        System.out.println("请输入项数N：");
        int counter = in.nextInt();
        if(counter<=1)
        {
            System.out.println("1");
            return;
        }
        if(counter==2)
        {
            System.out.println("1 ,1");
            return;
        }

        int a1 = 1;
        int a2 = 1;
        int a3;
        System.out.print("斐波那契数列前"+counter+"项是:");
        System.out.print(a1 + "," + a2);
        for (int i = 3; i <= counter; i++) {
            //2.根据前两个数算出第三个数
            a3 = a2 + a1;
            //3.更新第一第二个数
            a1 = a2;
            a2 = a3;
            System.out.print("," + a3);
        }
    }
}
